import os
import struct
import DataExtraction.BSAHeader

class BSAHeaderCIF(DataExtraction.BSAHeader.BSAHeader):
    def __init__(self, u1 = 0, u2 = 0, width = 0, height = 0, flags = 0, record_size = 0):
        DataExtraction.BSAHeader.BSAHeader.__init__(self, width, height)
        self._u1 = u1
        self._u2 = u2
        self._flags = flags
        self._record_size = record_size
        
        # 6 WORD's
        self._unpack_fmt = 6 * 'H'
        self._size_in_bytes = struct.calcsize(self._unpack_fmt)
    
    def __repr__(self):
        return "BSAHeaderCIF: [width=" + str(self.get_width()) +\
            "|height=" + str(self.get_height()) + "|u1=" + \
            str(self._u1) + "|u2=" + str(self._u2) + "|flags=" + str(self._flags) +\
            "|record_size=" + str(self._record_size) + "]"
            
    # getters
    def get_u1(self):
        return self._u1
    
    def get_u2(self):
        return self._u2
    
    def get_flags(self):
        return self._flags
    
    def get_record_size(self):
        return self._record_size
    
    # setters
    def set_u1(self, u1):
        self._u1 = u1
        
    def set_u2(self, u2):
        self._u2 = u2
        
    def set_flags(self, flags):
        self._flags = flags
        
    def set_record_size(self, record_size):
        self._record_size = record_size
        
    def load(self, global_bsa_data, start):
    #def load (self, global_bsa_data):
        curr_offset = global_bsa_data.tell()
        
        global_bsa_data.seek(start, os.SEEK_SET)
        
        r = global_bsa_data.read(self._size_in_bytes)
        
        self._u1, self._u2, self._width, self._height, self._flags,\
            self._record_size = struct.unpack(self._unpack_fmt, r)
        
        global_bsa_data.seek(curr_offset, os.SEEK_SET)